{% extends 'layout.html' %}

{% load rbac %}

<!-- 当前页面的css样式 -->
{% block css %}
    <style>
        tr.active > td > a {
            background: rgb(45, 115, 169);
            color: white;
        }

        tr.active > td > a:hover {
            background: rgb(45, 115, 169);
            color: white;
        }

        table {
            font-size: 12px;
        }

        .panel-body {
            font-size: 12px;
        }
    </style>
{% endblock %}

<!-- 当前页面：菜单编辑页面 -->
{% block content %}
    <div class="content-container">
        <!-- 一级菜单 -->
        <div class="col-md-12 ">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <i class="fa fa-th-large" aria-hidden="true"></i> 一级菜单
                    <a href="{% memory_url request 'rbac:menu_add' %}" class="right btn btn-success btn-xs"
                       style="padding: 2px 8px;margin: -3px;">
                        <i class="fa fa-plus" aria-hidden="true"></i>
                        新建
                    </a>
                </div>
                <!-- Table -->
                <table class="table table-bordered table-hover">
                    <thead>
                    <tr>
                        <th>名称</th>
                        <th style="text-align: center" width="80">选项</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for row in menus %}
                        <tr class="{% if row.id|safe == menu_id %}active{% endif %}">
                            <td>
                                <a href="?mid={{ row.id }}" class="btn btn-default btn-sm">
                                    <i class="fa {{ row.icon }}" aria-hidden="true"></i>
                                    {{ row.title }}
                                </a>
                            </td>
                            <td style="text-align: center" width="80">
                                <div class="pull-right">
                                    <a class="text-primary" style="margin-right: 10px;"
                                       href="{% memory_url request 'rbac:menu_edit' pk=row.id %}">
                                        编辑
                                    </a>
                                    <a class="text-danger" href="{% memory_url request 'rbac:menu_del' pk=row.id %}">
                                        删除
                                    </a>
                                </div>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
        <!-- 二级菜单 -->
        <div class="col-md-9 col-md-offset-3">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <i class="fa fa-th-list" aria-hidden="true"></i> 二级菜单
                    <!-- 只有选中一级菜单，才可以添加二级菜单 -->
                    {% if menu_id %}
                        <a href="{% memory_url request 'rbac:second_menu_add' menu_id=menu_id %}"
                           class="right btn btn-success btn-xs"
                           style="padding: 2px 8px;margin: -3px;">
                            <i class="fa fa-plus" aria-hidden="true"></i>
                            新建
                        </a>
                    {% endif %}
                </div>
                <!-- Table -->
                <table class="table">
                    <thead>
                    <tr>
                        <th>名称</th>
                        <th>CODE&URL</th>
                        <th style="text-align: right">选项</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for row in second_menus %}
                        <tr class="{% if row.id|safe == second_menu_id %}active {% endif %}">
                            <td rowspan="2">
                                <a href="?mid={{ menu_id }}&sid={{ row.id }}"
                                   class="btn btn-default btn-sm">{{ row.title }}</a>
                            </td>
                            <td>{{ row.name }}</td>
                            <td>
                                <div class="pull-right">
                                    <a class="text-primary" style="margin-right: 10px;"
                                       href="{% memory_url request 'rbac:second_menu_edit' pk=row.id %}">
                                        编辑
                                    </a>
                                    <a class="text-danger"
                                       href="{% memory_url request 'rbac:second_menu_del' pk=row.id %}">
                                        删除
                                    </a>
                                </div>
                            </td>
                        </tr>
                        <tr class="{% if row.id|safe == second_menu_id %}active {% endif %}">
                            <td colspan="2" style="border-top: 0">{{ row.url }}</td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
        <!-- 非菜单的权限（三级菜单） -->
        <div class="col-md-6 col-md-offset-6">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <i class="fa fa-check-circle" aria-hidden="true"></i> 权限
                    <!-- 只有选中二级菜单，才可以添加三级菜单 -->
                    {% if second_menu_id %}
                        <a href="{% memory_url request 'rbac:permission_add' second_menu_id=second_menu_id %}"
                           class="right btn btn-success btn-xs"
                           style="padding: 2px 8px;margin: -3px;">
                            <i class="fa fa-plus" aria-hidden="true"></i>
                            新建
                        </a>
                    {% endif %}
                </div>
                <!-- Table -->
                <table class="table">
                    <thead>
                    <tr>
                        <th>名称</th>
                        <th>CODE&URL</th>
                        <th>选项</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for row in permissions %}
                        <tr>
                            <td rowspan="2">{{ row.title }}</td>
                            <td>{{ row.name }}</td>
                            <td>
                                <div class="pull-right">
                                    <a class="text-primary" style="margin-right: 10px;"
                                       href="{% memory_url request 'rbac:permission_edit' pk=row.id %}">
                                        编辑
                                    </a>
                                    <a class="text-danger"
                                       href="{% memory_url request 'rbac:permission_del' pk=row.id %}">
                                        删除
                                    </a>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" style="border-top: 0">{{ row.url }}</td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
{% endblock %}